var vote = new Vue({
    el: '#Votelist',
    data: {
        userId: $("#id").val(),
        xiangmuId: $("#xiangmuId").val(),
        xiangmuleixing: $("#xiangmuleixing").val(),

        usernum: '',
        drugname: '',
        jicaiyao: '',
        jiyao: '',

        xiangmu: {},
        votelist: [],
        show: false,
        total: 0,
        tongyishu: 0,
        butongyishu: 0,

        pinguiList: [],
        pinpaiList: [],
        pinzhongList: [],

        qiyepass: '',
        totalnum: '',
        jicaipass: '',
        jicaishengyu: '',

        issubmited: false,
        isallsubmited: false,

        pageIndex: 1,
        pageSize: 9999,
        pageCount: 0,
        recordCount: 0,
        inputPageIndexValue: "",
        getCount: 1,

        passcount: 0,
        totalcount: 0,
        needcount: 0,
        keshi: "",
        
        paginationData: [],
    },
    computed: {
        getCounttext: function () {
            if(this.getCount == 1){
                return "品规"
            }else if(this.getCount == 2){
                return "品牌"
            }else if(this.getCount == 3){
                return "品种"
            }
        }
    },
    created: function () {
        var _this = this;
        window.toVote = this.toVote;
        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        
        // 检查URL中是否有页码参数
        var urlParams = new URLSearchParams(window.location.search);
        if (urlParams.has('pageIndex')) {
            _this.pageIndex = parseInt(urlParams.get('pageIndex')) || 1;
        }
        
        _this.findIsacticed();
    },
    methods: {
        isVoteAll: function (xiangmuLeixing) {
            return   IsVoteAll(xiangmuLeixing)
        },

        HuizongbiaoView: function () {
            location.href = "/TyController/HuizongbiaoView?xiangmuid=" + this.xiangmuId + "&xiangmuleixing=" + this.xiangmuleixing;
        },
        findIsacticed: function () {
            var _this = this;
            layer.open({type: 3});
            $.post('/xiangmu/find_one', {
                xianmguid: _this.xiangmuId,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId = _this.xiangmu.xiangmuid;
                        _this.xiangmuleixing = _this.xiangmu.xiangmuleixing;
                        _this.usernum = data.zhuangjiashu;
                        
                        // 如果是217项目类型，设置每页显示1个品种作为基础值
                        // 实际显示数量会在createHtml3函数中根据品规数量动态调整
                        if (_this.xiangmuleixing == "217"||_this.xiangmuleixing == "218") {
                            _this.pageSize = 1;
                        }
                        
                        _this.checkIsSubmited();
                        _this.checkIsAllSubmited();
                        _this.getResultCount();

                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        remove: function () {
            this.guigexuhao = "";
            this.drugname = "";
            this.jicaiyao = "";
            this.jiyao = "";
            this.findBiaojuelist();
        },
        toRefresh: function () {
            location.reload();
        },
        findBiaojuelist: function () {
            var _this = this;
            layer.open({type: 3});
            if(_this.xiangmuleixing == "217"||_this.xiangmuleixing == "218") {
                // 设置基础值为1个品种，实际显示数量会在createHtml3函数中动态调整
                _this.pageSize = 1;
                // 重置分页数据，以便重新计算
                _this.paginationData = [];
            }
            $.post("/TyController/findBiaojuelist", {
                xiangmuid: _this.xiangmuId,
                xiangmuleixing: _this.xiangmuleixing,
                userid: _this.userId,
                drugname: _this.drugname,
                pageindex: _this.pageIndex,
                pagesize: _this.pageSize,
                rdm: Math.random()
            }, function (ppData) {
                // layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.getCount = data.getCount;
                        _this.passcount = data.passcount;
                        _this.totalcount = data.totalcount;
                        _this.needcount = data.needcount;
                        _this.keshi = data.keshi;
                        window.lunci = data.lunci;
                        var mmHtml = ""
                        switch (data.Xunhuan) {
                            case 1:
                                mmHtml += _this.createHtml1(data, _this.xiangmuleixing);
                                break;
                            case 2:
                                mmHtml += _this.createHtml2(data, _this.xiangmuleixing);
                                break;
                            case 3:
                                mmHtml += _this.createHtml3(data, _this.xiangmuleixing);
                                break;
                        }
                        $("#List").html(mmHtml);
                        layer.closeAll("loading");
                    } else {
                        layer.alert(ppData.message);
                    }
                }

            }, "json");
        },
        createHtml1: function (data, xiangmuLeixing) {
            var _this = this
            var mmHtml = ""
            {
                mmHtml += createTitle(xiangmuLeixing, 1)
                if (data.pinguiList.length > 0) {
                    _this.show = true;
                    _this.pinguiList = data.pinguiList;

                    var PageInfo = data.PageInfo;
                    _this.pageIndex = PageInfo.pageIndex;
                    _this.recordCount = PageInfo.recordCount;
                    _this.pageCount = PageInfo.pageCount;


                    for (var i = 0; i < _this.pinguiList.length; i++) {
                        var mmpinguilist = _this.pinguiList[i]
                        var mmId = mmpinguilist.id
                        var mmResult = mmpinguilist.result

                        var mmPinguixuhao = 1

                        var mmBtndiv = "";

                        // 添加隔品规随机换色 - 注意这里不添加tr标签，因为createBody1已经包含了tr标签
                        var needColoring = (i % 2 === 0);

                        // 生成随机颜色
                        var randomColor1 = "lightblue";
                        var randomColor2 = "#ffffff";

                        // 替换createBody1中的tr标签
                        var bodyHtml = createBody1(xiangmuLeixing, mmpinguilist);
                        if (needColoring) {
                            bodyHtml = bodyHtml.replace('<tr>', '<tr style=\'background-color:' + randomColor1 + ';\'>');
                        }else {
                            bodyHtml = bodyHtml.replace('<tr>', '<tr style=\'background-color:' + randomColor2 + ';\'>');
                        }
                        mmHtml += bodyHtml;
                        if (_this.issubmited) {
                            if (mmResult == null || mmResult == 0) {
                                mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" disabled onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "')\" id='checkbox_" + mmId + "' class='cbcss' type=\"checkbox\"></div>";
                            }
                            if (mmResult == 1) {
                                mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" disabled checked onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "')\" id='checkbox_" + mmId + "' class='cbcss' type=\"checkbox\"></div>";
                            }
                        }
                        if (!_this.issubmited) {
                            if (mmResult == null || mmResult == 0) {
                                mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "')\" id='checkbox_" + mmId + "' class='cbcss' type=\"checkbox\"></div>";
                            }
                            if (mmResult == 1) {
                                mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" checked onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "')\" id='checkbox_" + mmId + "'  class='cbcss' type=\"checkbox\"></div>";
                            }
                        }

                        mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px'>" + mmBtndiv + "</td>";
                        mmHtml += "</tr>";
                    }

                }
            }
            return mmHtml + "</tbody></table>";


        },
        createHtml2: function (data, xiangmuLeixing) {
            var _this = this
            {
                var mmHtml = ""
                mmHtml += createTitle(xiangmuLeixing, 1)
                if (data.pinpaiList.length > 0) {
                    _this.show = true;
                    _this.pinpaiList = data.pinpaiList;

                    var PageInfo = data.PageInfo;
                    _this.pageIndex = PageInfo.pageIndex;
                    _this.recordCount = PageInfo.recordCount;
                    _this.pageCount = PageInfo.pageCount;

                    for (var i = 0; i < _this.pinpaiList.length; i++) {
                        var pinpaiONE = _this.pinpaiList[i].pinpaione
                        var pinguiList = _this.pinpaiList[i].pinguiList
                        var mmPinpaiXuhao = _this.pinpaiList[i].pinpaixuhao;
                        var mmPinguiHebingshu = _this.pinpaiList[i].pinguihebinghang;

                        for (var j = 0; j < pinguiList.length; j++) {
                            var mmpinguiONE = pinguiList[j]
                            var mmId = mmpinguiONE.id
                            var mmResult = mmpinguiONE.result
                            var mmPinguixuhao = mmpinguiONE.id;

                            var mmBtndiv = "";
                            var mmerjihe = "";

                            // 添加隔品规随机换色
                            var bodyHtml = createBody2(xiangmuLeixing, j, mmpinguiONE, mmPinguiHebingshu);
                            // 根据品规索引决定是否添加颜色
                            var pinguiNeedColoring = (i % 2 === 0);
                            // 生成随机颜色
                            var randomColor1 =  "lightblue";
                            var randomColor2 =  "#ffffff";

                            if (pinguiNeedColoring) {
                                // 由于createBody2以<tr>开头，我们需要替换这个标签
                                bodyHtml = bodyHtml.replace('<tr>', '<tr style="background-color:' + randomColor1 + ';">');
                            }else {
                                bodyHtml = bodyHtml.replace('<tr>', '<tr style="background-color:' + randomColor2 + ';">');
                            }
                            mmHtml += bodyHtml;
                            if (_this.issubmited) {
                                if (mmResult == null || mmResult == 0) {
                                    mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 100px;height: 30px;\" disabled onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "','" + mmPinpaiXuhao + "')\" id='checkbox_" + mmId + "' class='cbcss' type=\"checkbox\"></div>";
                                }
                                if (mmResult == 1) {
                                    mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 100px;height: 30px;\" disabled checked onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "','" + mmPinpaiXuhao + "')\" id='checkbox_" + mmId + "' class='cbcss' type=\"checkbox\"></div>";
                                }
                            }
                            if (!_this.issubmited) {
                                if (mmResult == null || mmResult == 0) {
                                    mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 100px;height: 30px;\" onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "','" + mmPinpaiXuhao + "')\" id='checkbox_" + mmId + "' class='cbcss' type=\"checkbox\"></div>";
                                }
                                if (mmResult == 1) {
                                    mmBtndiv = "<div id='div_" + mmId + "' style=\"text-align:center;\"><input style=\"width: 100px;height: 30px;\" checked onclick=\"toVote('" + mmId + "','" + mmPinguixuhao + "','" + mmPinpaiXuhao + "')\" id='checkbox_" + mmId + "'  class='cbcss' type=\"checkbox\"></div>";
                                }
                            }
                            if (IsVotePinpai(xiangmuLeixing)) {
                                if (j === 0) {
                                    mmerjihe = ""
                                    mmerjihe += "<td style='text-align:center;vertical-align:middle;height: 100%;width: 100px;'  rowspan='" + mmPinguiHebingshu + "'>" + mmBtndiv + "</td>";

                                }
                                mmHtml += mmerjihe;
                            } else {
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;'>" + mmBtndiv + "</td>";
                            }

                            mmHtml += "</tr>";
                        }
                    }

                }
            }
            return mmHtml + "</tbody></table></div>";

        },
        createHtml3: function (data, xiangmuLeixing) {
            var _this = this;
            var mmHtml = "";
            mmHtml += createTitle(xiangmuLeixing, 1)

            if (data.pinzhongList && data.pinzhongList.length > 0) {
                _this.show = true;
                _this.pinzhongList = data.pinzhongList;

                var PageInfo = data.PageInfo;
                _this.pageIndex = PageInfo.pageIndex;
                _this.recordCount = PageInfo.recordCount;
                _this.pageCount = PageInfo.pageCount;

                // 获取后端返回的列索引
                var pinpaixuhao = data.pinpaixuhao;
                var pinzhongxuhao = data.pinzhongxuhao;
                
                // 预处理计算每个品种的总行数
                for (var i = 0; i < _this.pinzhongList.length; i++) {
                    var pinzhongONE = _this.pinzhongList[i];
                    var totalRows = 0;
                    
                    // 计算该品种下所有品牌的品规总数
                    for (var j = 0; j < pinzhongONE.pinpaiList.length; j++) {
                        var pinpaiONE = pinzhongONE.pinpaiList[j];
                        totalRows += pinpaiONE.pinguiList.length;
                    }
                    
                    // 更新品种的合并行数
                    pinzhongONE.pinguihebinghang = totalRows;
                }

                // 品种颜色设置 - 奇数偶数两种颜色
                // var pinzhongColorOdd = "#D9E1F4";  // 品种奇数行颜色
                // var pinzhongColorEven = "#FCE4D3"; // 品种偶数行颜色
                var pinzhongColorOdd = "#ffffff";  // 品种奇数行颜色
                var pinzhongColorEven = "lightblue"; // 品种偶数行颜色
                
                // 添加品牌计数器，用于隔行换色
                var brandColorCounter = 0;
                // 存储品牌颜色的数组
                var brandColors = [];
                
                // 当项目类型为217时，只显示当前页的品种
                var displayPinzhongList = _this.pinzhongList;
                if (xiangmuLeixing == "217"||xiangmuLeixing == "218") {
                    // 记录总品种数
                    _this.recordCount = _this.pinzhongList.length;
                    
                    // 如果还没有预计算分页数据，则进行计算
                    if (_this.paginationData.length === 0) {
                        // 预计算所有分页信息
                        _this.paginationData = _this.calculatePaginationData(_this.pinzhongList);
                    }
                    
                    // 设置总页数
                    _this.pageCount = _this.paginationData.length;
                    
                    // 确保当前页码有效
                    if (_this.pageIndex > _this.pageCount) {
                        _this.pageIndex = _this.pageCount;
                    }
                    
                    // 获取当前页的品种列表
                    if (_this.pageIndex <= _this.paginationData.length) {
                        displayPinzhongList = _this.paginationData[_this.pageIndex - 1].items;
                    } else {
                        displayPinzhongList = [];
                    }
                }

                for (var i = 0; i < displayPinzhongList.length; i++) {
                    var pinzhongONE = displayPinzhongList[i];
                    var pinpaiList = pinzhongONE.pinpaiList;
                    var mmPinzhongXuhao = pinzhongONE.pinzhongone[pinzhongxuhao];
                    var mmPinzhongHebingshu = pinzhongONE.pinguihebinghang;
                    
                    // 根据品种索引确定颜色
                    var pinzhongColor = (i % 2 === 0) ? pinzhongColorOdd : pinzhongColorEven;
                    
                    // 设置全局变量，供createBody3函数使用
                    window.currentPinzhongColor = pinzhongColor;
                    
                    for (var j = 0; j < pinpaiList.length; j++) {
                        var pinpaiONE = pinpaiList[j];
                        var pinguiList = pinpaiONE.pinguiList;
                        var mmPinpaiXuhao = pinpaiONE.pinpaione[pinpaixuhao];
                        var mmPinguiHebingshu = pinpaiONE.pinguihebinghang;
                        
                        // 每次切换品牌时，增加计数器，用于隔行换色
                        brandColorCounter++;
                        // 确定当前品牌行是否需要着色
                        var needColoring = (brandColorCounter % 2 === 1);

                        // 为每个需要着色的品牌设置颜色
                        if (needColoring) {
                            brandColors[j] = "#ffffff";
                        } else {
                            brandColors[j] = "lightblue";
                        }
                        brandColors[j] = pinzhongColor
                        for (var k = 0; k < pinguiList.length; k++) {
                            var mmpinguiONE = pinguiList[k];
                            var mmId = mmpinguiONE.id;
                            var mmResult = mmpinguiONE.result;
                            var mmPinguixuhao = mmpinguiONE.id;
                            
                            // 判断是否是品种的第一行和品牌的第一行
                            var isFirstPinzhong = (j === 0 && k === 0);
                            var isFirstPinpai = (k === 0);
                            
                            // 使用品牌对应的颜色
                            var trStyle = ' style="background-color:' + brandColors[j] + ';"';
                            mmHtml += "<tr" + trStyle + ">";

                            // 使用createBody3函数来创建表格行内容
                            mmHtml += createBody3(xiangmuLeixing, k, j, mmpinguiONE, mmPinguiHebingshu, mmPinzhongHebingshu, isFirstPinpai, isFirstPinzhong);
                            
                            // 处理投票按钮
                            var mmBtndiv = "";
                            if (_this.issubmited) {
                                if (mmResult == null || mmResult == 0) {
                                    mmBtndiv = `<div id='div_${mmId}' style="text-align:center;"><input style="width: 30px;height: 30px;" disabled onclick="toVote('${mmId}','${mmPinguixuhao}','${mmPinpaiXuhao}','${mmPinzhongXuhao}')" id='checkbox_${mmId}' class='cbcss' type="checkbox"></div>`;
                                } else {
                                    mmBtndiv = `<div id='div_${mmId}' style="text-align:center;"><input style="width: 30px;height: 30px;" disabled checked onclick="toVote('${mmId}','${mmPinguixuhao}','${mmPinpaiXuhao}','${mmPinzhongXuhao}')" id='checkbox_${mmId}' class='cbcss' type="checkbox"></div>`;
                                }
                            } else {
                                if (mmResult == null || mmResult == 0) {
                                    mmBtndiv = `<div id='div_${mmId}' style="text-align:center;"><input style="width: 30px;height: 30px;" onclick="toVote('${mmId}','${mmPinguixuhao}','${mmPinpaiXuhao}','${mmPinzhongXuhao}')" id='checkbox_${mmId}' class='cbcss' type="checkbox"></div>`;
                                } else {
                                    mmBtndiv = `<div id='div_${mmId}' style="text-align:center;"><input style="width: 30px;height: 30px;" checked onclick="toVote('${mmId}','${mmPinguixuhao}','${mmPinpaiXuhao}','${mmPinzhongXuhao}')" id='checkbox_${mmId}' class='cbcss' type="checkbox"></div>`;
                                }
                            }
                            
                            // 处理不同投票模式
                            var mmerjihe = "";
                            
                            // 处理品种投票模式
                            if (IsVotePinzhong(xiangmuLeixing)) {
                                if (isFirstPinzhong) {
                                    mmerjihe = `<td style='background-color:${pinzhongColor};text-align:center;vertical-align:middle;width:100px;' rowspan='${mmPinzhongHebingshu}'>${mmBtndiv}</td>`;
                                    mmHtml += mmerjihe;
                                }
                            }
                            // 处理品牌投票模式
                            else if (IsVotePinpai(xiangmuLeixing)) {
                                if (isFirstPinpai) {
                                    mmerjihe = `<td style='text-align:center;vertical-align:middle;width:100px;' rowspan='${mmPinguiHebingshu}'>${mmBtndiv}</td>`;
                                    mmHtml += mmerjihe;
                                }
                            }
                            // 处理品规投票模式（默认）
                            else {
                                mmHtml += `<td style='text-align:center;vertical-align:middle;width:100px;'>${mmBtndiv}</td>`;
                            }
                            mmHtml += "</tr >";
                        }
                    }
                }
            }
            
            return mmHtml + "</tbody></table></div>";
        },
        toVote: function (ppId, ppPingui, ppPinpai, ppPinzhong) {
            var _this = this
            var ppResult = "";
            if ($("#checkbox_" + ppId).is(":checked")) {
                ppResult = "1";
            } else {
                ppResult = "0";
            }
            layer.open({type: 3});
            $.post('/TyController/vote', {
                id: ppId,
                pinguixuhao: ppPingui,
                pinpaixuhao: ppPinpai,
                pinzhongxuhao: ppPinzhong,
                userid: $("#id").val(),
                xiangmuleixing: $("#xiangmuleixing").val(),
                xiangmuid: $("#xiangmuId").val(),
                result: ppResult,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        _this.getResultCount();

                    } else {
                        layer.alert(ppData.message);
                        $("#checkbox_" + ppId).prop("checked", false);
                    }
                }
            }, "json");
        },
        getResultCount: function () {
            var _this = this;
            layer.open({type: 3});
            $.post('/TyController/getResultCount', {
                xiangmuid: _this.xiangmuId,
                xiangmuleixing: _this.xiangmuleixing,
                userid: _this.userId,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.qiyepass = data.qiyepass;
                        _this.totalnum = data.totalnum;
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        checkIsSubmited: function () {
            var _this = this;
            layer.open({type: 3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid: _this.xiangmuId,
                userid: _this.userId,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        if (ppData.resultContent == "1") {
                            _this.issubmited = true;
                        }
                        _this.findBiaojuelist();
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        checkIsAllSubmited: function () {
            var _this = this;
            layer.open({type: 3});
            $.post('/renyuanfenpei/checkIsAllSubmited', {
                xiangmuid: _this.xiangmuId,
                userid: _this.userId,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        if (ppData.resultContent == "1") {
                            _this.isallsubmited = true;
                        }
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        voteAll: function (ppresult) {
            var _this = this;
            layer.open({type: 3});
            $.post('/TyController/voteAll', {
                xiangmuid: _this.xiangmuId,
                xiangmuleixing: _this.xiangmuleixing,
                userid: _this.userId,
                result:ppresult,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        location.reload()
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        tosubmit: function () {
            var _this = this;
            // layer.confirm("总共"+_this.totalnum+"项，您已勾选"+_this.qiyepass+"项，未勾选"+(_this.totalnum-_this.qiyepass)+"项，是否确认提交？", {
            layer.confirm("是否确认提交？", {
                btn: ['是', '否'],title:"确认提交"
            }, function () {
                layer.open({type: 3});
                $.post('/TyController/submit', {
                    xiangmuid: _this.xiangmuId,
                    xiangmuleixing: _this.xiangmuleixing,
                    userid: _this.userId,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.closeAll("loading");
                    if (ppData != null) {
                        if (ppData.result == "1") {
                            _this.issubmited = true;
                            layer.alert("提交成功");
                            _this.findBiaojuelist();

                            setTimeout(function () {
                                _this.checkIsAllSubmited();
                            }, 5000);

                        } else {
                            layer.confirm(ppData.message, {
                                btn: ['确定', '取消']
                            }, function(){
                                layer.closeAll()
                            }, function(){
                            });

                        }
                    }
                }, "json");
            })
        },
        //跳到首页
        SetPageIndex: function () {
            this.pageIndex = 1;
            this.updateUrlWithPageIndex();
        },
        SetPageEnd: function () {
            this.pageIndex = this.pageCount;
            this.updateUrlWithPageIndex();
        },
        //上一页
        SetPageIndexPrePage: function () {
            var PrePage = ((this.pageIndex - 1) <= 0) ? 1 : (this.pageIndex - 1);
            this.pageIndex = PrePage;
            this.updateUrlWithPageIndex();
        },
        //下一页
        SetPageIndexNextPage: function () {
            var NextPage = ((this.pageIndex + 1) >= this.pageCount) ? this.pageCount : (this.pageIndex + 1);
            this.pageIndex = NextPage;
            this.updateUrlWithPageIndex();
        },
        //跳转界面
        JumpPage: function () {
            if (this.inputPageIndexValue <= 1) {
                this.inputPageIndexValue = 1;
            } else if (this.inputPageIndexValue >= this.pageCount) {
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
            this.updateUrlWithPageIndex();
        },
        // 更新URL中的页码参数
        updateUrlWithPageIndex: function() {
            if (this.xiangmuleixing == "217"||this.xiangmuleixing == "218") {
                // 确保页码在有效范围内
                var validPageIndex = Math.max(1, Math.min(this.pageIndex, this.pageCount));
                
                var url = new URL(window.location.href);
                url.searchParams.set('pageIndex', validPageIndex);
                window.history.replaceState({}, '', url);
            }
        },
        calculatePaginationData: function(pinzhongList) {
            var paginationData = [];
            var currentPage = [];
            var currentPagePinguiTotal = 0;
            var addedPinzhongIds = new Set();
            
            // 遍历所有品种
            for (var i = 0; i < pinzhongList.length; i++) {
                var pinzhong = pinzhongList[i];
                var pinzhongId = pinzhong.id || i;
                var pinguiCount = pinzhong.pinguihebinghang || 0;
                
                // 如果当前页为空，或者当前页品规总数少于8个，则添加到当前页
                if (currentPage.length === 0 || (currentPagePinguiTotal < 8 && !addedPinzhongIds.has(pinzhongId))) {
                    currentPage.push(pinzhong);
                    currentPagePinguiTotal += pinguiCount;
                    addedPinzhongIds.add(pinzhongId);
                } else {
                    // 当前页已满，创建新页
                    paginationData.push({
                        pageIndex: paginationData.length + 1,
                        items: currentPage.slice(), // 使用slice()创建数组的副本，避免引用
                        pinguiTotal: currentPagePinguiTotal
                    });
                    
                    // 重置当前页
                    currentPage = [pinzhong];
                    currentPagePinguiTotal = pinguiCount;
                    addedPinzhongIds = new Set();
                    addedPinzhongIds.add(pinzhongId);
                }
            }
            
            // 添加最后一页（如果有）
            if (currentPage.length > 0) {
                paginationData.push({
                    pageIndex: paginationData.length + 1,
                    items: currentPage.slice(), // 使用slice()创建数组的副本，避免引用
                    pinguiTotal: currentPagePinguiTotal
                });
            }
            
            return paginationData;
        },
    },
    watch: {

        //监控分页情况，刷新列表
        pageIndex: function () {
            this.findBiaojuelist();
        }

    }
})

/**
 * 生成随机浅色
 * 生成的颜色较浅，适合作为表格背景色
 * @returns {string} 返回十六进制颜色值
 */
function getRandomLightColor() {
    // 基础色值范围，确保生成的是浅色
    var r = Math.floor(Math.random() * 55) + 200; // 200-255
    var g = Math.floor(Math.random() * 55) + 200; // 200-255
    var b = Math.floor(Math.random() * 55) + 200; // 200-255

    // 转换为16进制
    var hexR = r.toString(16).padStart(2, '0');
    var hexG = g.toString(16).padStart(2, '0');
    var hexB = b.toString(16).padStart(2, '0');

    return "#" + hexR + hexG + hexB;
}